| Conditions | 1 |
| Paths | 1 |
| Total Lines | 61 |
| Lines | 61 |
| Ratio | 100 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | var assert = require('chai').assert, |
||
| 11 | View Code Duplication | it('Create with JSON', function(){ |
|
|
|
|||
| 12 | var agent = GedcomX.Agent({ |
||
| 13 | id: 'agent', |
||
| 14 | identifiers: { |
||
| 15 | $: 'ident' |
||
| 16 | }, |
||
| 17 | names: [ |
||
| 18 | { |
||
| 19 | lang: 'en', |
||
| 20 | value: 'Name' |
||
| 21 | } |
||
| 22 | ], |
||
| 23 | homepage: { |
||
| 24 | resource: 'http://homepage' |
||
| 25 | }, |
||
| 26 | openid: { |
||
| 27 | resource: 'http://openid' |
||
| 28 | }, |
||
| 29 | accounts: [ |
||
| 30 | { |
||
| 31 | accountName: 'jimbo' |
||
| 32 | } |
||
| 33 | ], |
||
| 34 | emails: [ |
||
| 35 | { |
||
| 36 | resource: 'http://email' |
||
| 37 | } |
||
| 38 | ], |
||
| 39 | phones: [ |
||
| 40 | { |
||
| 41 | resource: 'http://phone' |
||
| 42 | } |
||
| 43 | ], |
||
| 44 | addresses: [ |
||
| 45 | { |
||
| 46 | value: 'big long address', |
||
| 47 | postalCode: '123456' |
||
| 48 | } |
||
| 49 | ], |
||
| 50 | person: { |
||
| 51 | resource: 'http://person' |
||
| 52 | } |
||
| 53 | }); |
||
| 54 | assert.equal(agent.getId(), 'agent'); |
||
| 55 | assert.equal(agent.getIdentifiers().identifiers.$, 'ident'); |
||
| 56 | assert.equal(agent.getNames().length, 1); |
||
| 57 | assert.equal(agent.getNames()[0].getLang(), 'en'); |
||
| 58 | assert.equal(agent.getNames()[0].getValue(), 'Name'); |
||
| 59 | assert.equal(agent.getHomepage().getResource(), 'http://homepage'); |
||
| 60 | assert.equal(agent.getOpenid().getResource(), 'http://openid'); |
||
| 61 | assert.equal(agent.getAccounts().length, 1); |
||
| 62 | assert.equal(agent.getAccounts()[0].getAccountName(), 'jimbo'); |
||
| 63 | assert.equal(agent.getEmails().length, 1); |
||
| 64 | assert.equal(agent.getEmails()[0].getResource(), 'http://email'); |
||
| 65 | assert.equal(agent.getPhones().length, 1); |
||
| 66 | assert.equal(agent.getPhones()[0].getResource(), 'http://phone'); |
||
| 67 | assert.equal(agent.getAddresses().length, 1); |
||
| 68 | assert.equal(agent.getAddresses()[0].getValue(), 'big long address'); |
||
| 69 | assert.equal(agent.getAddresses()[0].getPostalCode(), '123456'); |
||
| 70 | assert.equal(agent.getPerson().getResource(), 'http://person'); |
||
| 71 | }); |
||
| 72 | |||
| 218 | }); |